#include "doublelist.h"
int main(int argc, char** argv) {
	DoubleList d1;
	d1.insertAtHead(1);
	d1.insertAtHead(2);
	d1.insertAtHead(3);
	d1.insertAtHead(4);
	d1.printDllForward();
	d1.printDllBackward();
	DoubleList d2;
	d2.insertAtTail(1);
	d2.insertAtTail(2);
	d2.insertAtTail(3);
	d2.insertAtTail(4);
	d2.printDllForward();
	d2.printDllBackward();
	
	std::cout<<"list is size: "<<d1.getSzie()<<std::endl;
	
	std::cout<<"测试删除头节点：";
	d2.deleteAtHead();
	d2.printDllForward();
	
	std::cout<<"测试删除尾节点：";
	d2.deleteAtTail();
	d2.printDllForward();
	
	std::cout<<"测试删除指定值节点：";
	d1.deleteValue(1);
	d1.printDllForward();
	
	std::cout<<"测试删除指定位置节点：";
	d1.deleteAtPosition(0);
	d1.printDllForward();
	
	DoubleList d3;
	d3.insertAtTail(1);
	d3.insertAtTail(2);
	d3.insertAtTail(3);
	d3.insertAtTail(4);
	d3.insertAtTail(2);
	
	
	std::cout<<"测试findFirst: ";
	NodePtr node = d3.findFirst(3);
	std::cout<<node->val<<std::endl;
	
	std::cout<<"测试findAll：";
	std::vector<NodePtr> temp = d3.findAll(2);
	for(auto Node : temp)
		std::cout<<Node->val<<" ";
	std::cout<<std::endl;
	
	std::cout<<"一个节点的大小：";
	std::cout<<sizeof(NodePtr)<<std::endl;
	
	std::cout<<"打印特定节点的地址：";
	std::cout<<std::endl;
	
	for(auto iter = temp.cbegin(); iter != temp.cend(); ++iter)
		std::cout<<*iter<<std::endl;
	
	std::cout<<"测试getNodeAt:";
	NodePtr temNode =  d3.getNodeAt(9);
	if(temNode)
		std::cout<<temNode->val;
	else
		std::cout<<"位置错误！"<<std::endl;	
	
	std::cout<<"测试findMiddle:";
	NodePtr middleNode = d3.findMiddle();
	
	if(middleNode)
		std::cout<<middleNode->val<<std::endl;
	else
		std::cout<<"查找错误"<<std::endl;
	
	bool flag = d3.hasCircle();
	
	if(flag)
		std::cout<<"是循环链表"<<std::endl;
	else
		std::cout<<"不是循环链表"<<std::endl;
	
	std::cout<<"测试findFirstIf: ";
	std::function<bool(int)> func_1;
	// 正确的lambda表达式赋值
	func_1 = [](int val) {
		if (val % 2 == 0) {
			return true;
		}
		return false;
	};
	NodePtr evenNode = d3.findFirstIf(func_1);
	if(evenNode)
		std::cout<<"查找到了，节点值为："<<evenNode->val<<std::endl;
	else
		std::cout<<"查找不到该节点"<<std::endl;
	
	
	std::cout<<"测试findAllIf: ";
	std::vector<NodePtr> evenAllNode = d3.findAllIf(func_1);
	if(evenAllNode.size()){
		for (auto tempNode : evenAllNode){
			std::cout<<tempNode->val<<" ";
		}
		std::cout<<std::endl;
	}else{
		std::cout<<"查找节点失败！"<<std::endl;
	}
	
	std::cout<<"测试getPosition：";
	NodePtr temPos = d3.getNodeAt(2);
	int pos = d3.getPosition(temPos);
	std::cout<<"postion is: "<<pos<<std::endl;
	
	std::cout<<"测试contains：";
	if(d3.contains(temPos))
		std::cout<<"查找到该节点: "<<temPos->val<<std::endl;
	else
		std::cout<<"查抄不到该节点"<<std::endl;
	
	std::cout<<"测试containsValue：";
	if(d3.containsValue(2))
		std::cout<<"查找到该值！"<<std::endl;
	else
		std::cout<<"查找失败!"<<std::endl;
	
	std::cout<<"测试findMax：";
	auto result = d3.findMax();
	if (result.first != nullptr) {
		std::cout << "最大值节点的值是: " << result.second << std::endl;
	}
	
	std::cout<<"测试insertBatchAtHead：\n";
	DoubleList dList;
	dList.insertBatchAtHead(std::vector<int> {1,2,3,4,5,6});
	dList.printDllForward();
	dList.printDllBackward();
	
	std::cout<<"\n测试insertBatchAtTail:\n";
	DoubleList dList2;
	dList2.insertBatchAtTail(std::vector<int> {1,2,3,4,5,6});
	dList2.printDllForward();
	dList2.printDllBackward();

	std::cout<<"测试sort: \n";
	DoubleList dList3;
	dList3.insertBatchAtTail(std::vector<int> {4,1,2,3});
	dList3.printDllForward();
	dList3.sort();
	dList3.printDllForward();
	return 0;
}
